package com.watson;

import java.util.HashSet;
import java.util.Set;

public class Application {

    private static final int MAX_NUM = 500000;
    private static final int startNum = 5000000;

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        Set<String> uvSet1 = genUid(startNum, MAX_NUM);
        Set<String> uvSet2 = genUid(MAX_NUM + startNum, MAX_NUM);
        Set<String> uvSet3 = genUid(MAX_NUM * 2 + startNum, MAX_NUM);
        Set<String> uvSet4 = genUid(MAX_NUM * 3 + startNum, MAX_NUM);

        long midTime = System.currentTimeMillis();
        System.out.println("mid time: " + String.valueOf(midTime - startTime));

        boolean b = uvSet1.addAll(uvSet2);
        boolean b1 = uvSet1.addAll(uvSet3);
        boolean b2 = uvSet1.addAll(uvSet4);
        long endTime = System.currentTimeMillis();
        if (b && b1 && b2) {
            System.out.println("ok");
        } else {
            System.out.println("failed");
        }
        System.out.println("last time: " + String.valueOf(endTime - midTime));
        Object object;

    }

    public static Set<String> genUid(int startNum, int maxNum) {
        Set<String> uv = new HashSet<>();
        String uid = "0000000000000000000000000000000000000000000000000000000000000000";
        int i = startNum;
        while (i < maxNum + startNum) {
            i++;
            uv.add(uid);
            String id = String.valueOf(i);
            StringBuffer tmpbuffer = new StringBuffer();
            tmpbuffer.append(uid, 0, uid.length() - id.length()).append(id);
            uid = tmpbuffer.toString();
        }

        return uv;
    }
}
